package top.liuzhenyu.springboot3.entity.auth;

import com.baomidou.mybatisplus.annotation.FieldStrategy;
import com.baomidou.mybatisplus.annotation.IdType;
import com.baomidou.mybatisplus.annotation.TableField;
import com.baomidou.mybatisplus.annotation.TableId;
import jakarta.validation.constraints.NotBlank;
import lombok.Data;
import org.hibernate.validator.constraints.Length;
import top.liuzhenyu.springboot3.validate.CommonValidate;

import java.io.Serial;
import java.io.Serializable;
import java.util.Date;

@Data
public class TbUser implements Serializable {
    @Serial
    private static final long serialVersionUID = 1L;
    // 自增主键
    @TableId(type = IdType.AUTO)
    private Integer id;

    @NotBlank(message = "登录名必须填写", groups = {CommonValidate.Add.class})
    @Length(min = 3, max = 16, message = "登录名长度必须在3-16位之间", groups = {CommonValidate.Add.class})
    private String username;
    @NotBlank(message = "密码必须填写", groups = {CommonValidate.Add.class,CommonValidate.Edit.class})
    @Length(min = 6, max = 16, message = "密码长度必须在6-16位之间", groups = {CommonValidate.Add.class, CommonValidate.Edit.class})
    private String password;
    @NotBlank(message = "昵称必须填写", groups = {CommonValidate.Add.class})
    private String nickname;
    private String salt;
    @TableField(insertStrategy = FieldStrategy.NEVER, updateStrategy = FieldStrategy.NEVER)
    private String deleted;
    private Integer role;
    @TableField(insertStrategy = FieldStrategy.NEVER, updateStrategy = FieldStrategy.NEVER)
    private Date created;

    public TbUser view() {
        TbUser user = new TbUser();
        user.setId(id);
        user.setUsername(username);
        user.setNickname(nickname);
        user.setRole(role);
        user.setCreated(created);
        return user;
    }
}
